﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XGE.Console
{
    public class OutputCollection : System.Collections.CollectionBase
    {
        int Location = 0;
        private List<string> Output = new List<string>();

        private int OutputCount;
        /// <summary>
        /// Sets the Max output for the console on the screen
        /// </summary>
        public int MaxLineOutput
        {
            get { return OutputCount; }
            set { OutputCount = value;
            }
        }       

        public OutputCollection()
        {
            this.List.Clear();
            Output.Clear();
        }

        /// <summary>
        /// Add a new Command/Output to the output list
        /// </summary>
        /// <param name="Line"></param>
        public void AddNewLine(string Line)
        {
            List.Add(Line);
            UpdateOutput();
            Location++;
        }
        private void UpdateOutput()
        {
            if (Output.Count >= OutputCount)
            {
                Output.RemoveAt(0);
            }
                Output.Add((string)List[Location]);
        }

        public void Resize()
        {
            Output.Clear();
            for (int Lines = OutputCount; Lines > 0; Lines--)
            {
                
                Output.Add((string)List[Location - Lines]);
            }
        }

        public List<string> GetOutput()
        {
            return Output;
        }
        public void ScrollUp()
        {
            if (Location > OutputCount)
            {
                Location--;
                Output.RemoveAt(OutputCount-1);
                Output.Insert(0, (string)List[Location - 1]);
            }
        }
        public void ScrollDown()
        {
            if (OutputCount < List.Count && Location < List.Count)
            {
                Location++;
                Output.RemoveAt(0);
                Output.Insert(OutputCount - 1, (string)List[Location - OutputCount - 1]);
            }
       } 
        private void init()
        {
            List.Clear();
            Output.Clear();
            Location = 0;
        }

    }
}
